package com.sgb.kjwl.view.ui.activity.self.company

import android.content.Context
import android.content.Intent
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.google.android.material.tabs.TabLayout
import com.sgb.kjwl.AppActivity
import com.sgb.kjwl.R
import com.sgb.kjwl.databinding.ActivityPriceCompetitionBinding
import com.sgb.kjwl.di.self.DaggerSelfComponent
import com.sgb.kjwl.di.self.SelfModule
import com.sgb.kjwl.view.ui.fragment.manage.OtherInquiryFragment
import com.sgb.kjwl.viewmodel.self.company.PriceCompetitionViewModel
import com.swgk.core.base.di.AppComponent
import javax.inject.Inject

/**
 * 竞价列表
 */
class PriceCompetitionActivity : AppActivity(){

    private lateinit var mBinding : ActivityPriceCompetitionBinding
    @Inject
    lateinit var mViewModel : PriceCompetitionViewModel

    private lateinit var mAdapter: PriceCompetitionAdapter

    companion object{
        private  val mTitles = arrayOf("收到的竞价", "发起的竞价")
        fun launch(context: Context){
            val intent  = Intent(context, PriceCompetitionActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        super.setupActivityComponent(appComponent)
        DaggerSelfComponent.builder().appComponent(appComponent)
            .selfModule(SelfModule()).build().inject(this)
    }

    override fun initView() {
        super.initView()
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_price_competition)
        mBinding.include.ivBack.setOnClickListener { finish() }
        mBinding.include.titleView.text = "竞价列表"
        renderFirstTab()
    }

    private fun renderFirstTab() {
        mAdapter = PriceCompetitionAdapter(supportFragmentManager)
        mBinding.viewPage.adapter = mAdapter
        mBinding.viewPage.offscreenPageLimit = mTitles.size
        mBinding.tablayout.setupWithViewPager(mBinding.viewPage)
        mBinding.tablayout.tabMode = TabLayout.MODE_FIXED
        mBinding.viewPage.currentItem = 0
    }


    class PriceCompetitionAdapter(fm : FragmentManager) : FragmentPagerAdapter(fm) {

        override fun getCount(): Int {
            return mTitles.size
        }

        override fun getItem(position: Int): Fragment {
            return OtherInquiryFragment.newInstance()
        }



        override fun getPageTitle(position: Int): CharSequence {
            return mTitles[position]
        }


    }


}